#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include<queue>
#include<stack>
using namespace std;
int sum[10000000];   
int main()
{
	unsigned long long t, l, r;
	unsigned long long a1=1, a2=2, a3=3, a4=4, a5=5, a6=6;
	sum[1] = 1;
	for (long long i = 2; i <= 10000000; i++)
	{
		a2 = (a2 * 2) % 7, a3 = (a3 * 3) % 7, a4 = (a4 * 4) % 7, a5 = (a5 * 5) % 7, a6 = (a6 * 6) % 7;
		sum[i] = a1 + a2 + a3 + a4 + a5 + a6;
		if (sum[i] % 7 == 0)
		{
			sum[i] = sum[i - 1] + 1;
		}
		else
			sum[i] = sum[i - 1];
	}
	cin >> t;
	while (t--)
	{
		cin >> l >> r;
		unsigned long long aa;
		aa = sum[r] - sum[l - 1];
		cout << aa << endl;
	}
	return 0;
}